Module-level declarations

Types

Link copied to clipboard

A cursor that points to where pages should start in paginated queries.

Link copied to clipboard

The return type of all paginated queries. It contains a list of results of the query, and a cursor which can be used to retrieve the next page.

In general, when a paginated query looks like this: get_my_data(page_size: integer?, page_cursor: text?)

  • page_size determines the number of results to be returned, defaulting to query_max_page_size as defined in the module args if null or higher than that value.

  • page_cursor determines where the results should start from, defaulting to the first page.

The returned results will be a paged result with:

  • data: a list of the expected data, encoded as GTVs

  • next_cursor: a base64 encoded page_cursor that can be passed as page_cursor to the same query to retrieve the next page of data

The cursors are not supposed to be interpreted in any way on the front-end. To avoid unexpected behavior, only pass cursors received from a query to that same query.

Link copied to clipboard

An element of a page that should be returned by paginated queries.

Link copied to clipboard

For complex validation we might not want to use simple "require()" but an error message that is returned.

Properties

Link copied to clipboard

The number of milliseconds in a day, mainly used for transfer time-to-live

Link copied to clipboard

A validation_result to be returned when no error should be thrown

Functions

Link copied to clipboard
function before_rowid(page_cursor: text?): rowid?

Returns the rowid of the last retrieved element, given the base64-encoded page_cursor.

Useful to retrieve the rowid where the last query stopped, to start retrieving a new page from there.

Link copied to clipboard
function convert_gtv_to_text(gtv: gtv, indentation_index: integer, in_dict: boolean): text

Converts a gtv value to a pretty text representation, with newlines and indentations. Used to create pretty auth messages which include all parameters passed to a certain operation, regardless of complexity.

It's still recommended to create custom auth messages for complex operations, as they will always be more readable than any automatically generated text.

Link copied to clipboard
function decode_cursor(cursor: text): page_cursor

Decodes a page_cursor from a base64 string, received as a query parameter.

Link copied to clipboard
function derive_nonce(op: gtx_operation, nonce: integer): text

A utility function that computes a unique nonce for this operation's message to sign.

Link copied to clipboard
function encode_cursor(page_cursor: page_cursor): text

Encodes a page_cursor into a base64 string to make it more manageable for the frontend

Link copied to clipboard
function fetch_data_size(page_size: integer?): integer

Used to calculate the page size for the current query. The value will be:

  • query_max_page_size if page_size is null or higher than that value

  • page_size otherwise

Link copied to clipboard
function invalid(error: text): validation_result

A validation_result to be returned when an error should be thrown

Link copied to clipboard
function is_big_integer(gtv: gtv): boolean

Used to check if a gtv value is encoding a big_integer

Link copied to clipboard
function is_byte_array(gtv: gtv): boolean

Used to check if a gtv value is encoding a byte_array

Link copied to clipboard
function is_dict(gtv: gtv): boolean

Used to check if a gtv value is encoding a dict

Link copied to clipboard
function is_integer(gtv: gtv): boolean

Used to check if a gtv value is encoding an integer

Link copied to clipboard
function is_list(gtv: gtv): boolean

Used to check if a gtv value is encoding a list

Link copied to clipboard
function is_text(gtv: gtv): boolean

Used to check if a gtv value is encoding a text

Link copied to clipboard
function latest_time(): integer

Returns the last block time regardless of whether op_context exists. Returns 0 if this is the first block.

Link copied to clipboard
function make_auth_message(message: text): text

A utility function that adds a header and a footer to every auth message.

The header contains the blockchain RID to avoid the same signature to be maliciously used on other chains in a cross-chain replay attack.

The footer contains a nonce to avoid the same signature to be maliciously used on this same chain in a classic replay attack.

Link copied to clipboard
function make_page(pagination_results: list<pagination_result>, page_size: integer?): paged_result

Creates a page from a list of pagination_results and the expected size of the page. It will never return pages bigger than query_max_page_size.

Used by paginated queries to build the actual paged_result that will be returned.

Throws "PAGE SIZE TOO SMALL" if page_size is less than 1

Link copied to clipboard

Utility function that returns an empty page with no next page

Link copied to clipboard
function validate_blockchain_rid(blockchain_rid: byte_array, descriptor: text)

Checks whether the blockchain RID has the correct size

Throws "INVALID BRID" if the RID's length is not 32 bytes.

Should be used inside other functions, and the descriptor parameter should be passed in a way that the error message is understood by the end users.

Example: validate_blockchain_rid(x"", "Chain X's RID") will throw this error: "INVALID BRID: Chain X's RID cannot be empty"